package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrAffair;
import com.ruoyi.system.service.ITrAffairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件编号Controller
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/system/affair")
public class TrAffairController extends BaseController
{
    @Autowired
    private ITrAffairService trAffairService;

    /**
     * 查询事件编号列表
     */
    @PreAuthorize("@ss.hasPermi('system:affair:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrAffair trAffair)
    {
        startPage();
        List<TrAffair> list = trAffairService.selectTrAffairList(trAffair);
        return getDataTable(list);
    }

    /**
     * 导出事件编号列表
     */
    @PreAuthorize("@ss.hasPermi('system:affair:export')")
    @Log(title = "事件编号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrAffair trAffair)
    {
        List<TrAffair> list = trAffairService.selectTrAffairList(trAffair);
        ExcelUtil<TrAffair> util = new ExcelUtil<TrAffair>(TrAffair.class);
        util.exportExcel(response, list, "事件编号数据");
    }

    /**
     * 获取事件编号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:affair:query')")
    @GetMapping(value = "/{affairId}")
    public AjaxResult getInfo(@PathVariable("affairId") Long affairId)
    {
        return success(trAffairService.selectTrAffairByAffairId(affairId));
    }

    /**
     * 新增事件编号
     */
    @PreAuthorize("@ss.hasPermi('system:affair:add')")
    @Log(title = "事件编号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrAffair trAffair)
    {
        return toAjax(trAffairService.insertTrAffair(trAffair));
    }

    /**
     * 修改事件编号
     */
    @PreAuthorize("@ss.hasPermi('system:affair:edit')")
    @Log(title = "事件编号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrAffair trAffair)
    {
        return toAjax(trAffairService.updateTrAffair(trAffair));
    }

    /**
     * 删除事件编号
     */
    @PreAuthorize("@ss.hasPermi('system:affair:remove')")
    @Log(title = "事件编号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{affairIds}")
    public AjaxResult remove(@PathVariable Long[] affairIds)
    {
        return toAjax(trAffairService.deleteTrAffairByAffairIds(affairIds));
    }
}
